package com.widevision.adapter;

import java.util.ArrayList;
import java.util.HashMap;


import com.widevision.ListActivity.FrndName;
import com.widevision.utility.ImageLoader;
import net.widevision.android.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FrndListAdapter extends BaseAdapter{
	
	 private Activity activity;
	 private static ArrayList<HashMap<String, String>> data;
	 private static LayoutInflater inflater=null;
	 public ImageLoader imageLoader; 
 
    public FrndListAdapter(Activity a, ArrayList<HashMap<String, String>> d)
    {
    	 activity = a;
         data=d;
         inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         imageLoader=new ImageLoader(activity.getApplicationContext());
    }
 
    
    public int getCount() {
    	 
      	 return data.size();
      }
   
      
      public Object getItem(int position) {
      	 return position;
      }
   
    
      public long getItemId(int position)
      {
      	return position;
      }
      
      
    public static class ViewHolder
    {
        TextView name;
        ImageView image;
        TextView userId;
       
    }
 
 
    public View getView(int position, View convertView, ViewGroup parent)
    {
    	final ViewHolder holder = new ViewHolder();
        if(convertView==null)
     
         
            convertView = inflater.inflate(R.layout.frndslistitem, null);
            holder.image = (ImageView) convertView.findViewById(R.id.frndimg);
            holder.name = (TextView) convertView.findViewById(R.id.frndname);
            holder.userId=(TextView) convertView.findViewById(R.id.userId);
            
            HashMap<String, String> frndmap = new HashMap<String, String>();
            
            frndmap = data.get(position);
            
            //SETTING ALL ITEM VALUES
       
	        holder.name.setText(frndmap.get(FrndName.FRND_NAME));
	        imageLoader.DisplayImage(frndmap.get(FrndName.FRND_THUMB_URL), holder.image);
	        holder.userId.setText(frndmap.get(FrndName.FRND_ID));
	        
	        convertView.setTag(holder);
	        return convertView;
    }
 
}

